✨ BCA JUL24 Batch ✨

Join Our WhatsApp Group

Anukasif Pic

5.2 - Structures - MCQs

Interactive MCQs Quiz

Test your knowledge with these questions

1. What is a structure in C?

2. Which keyword is used to define a structure in C?

3. How do you access members of a structure?

4. What does the following code declare?

struct stud {
                    char name[80];
                    int roll;
                    float mark;
                };

5. What will be the output of this code?

struct stud {
                    char name[80];
                    int roll;
                    float mark;
                } st;
                
                st.roll = 100;
                printf("%d", st.roll);

6. How can you define a structure variable without giving it a name?

7. What does the sizeof operator return when used with a structure?

8. Which of the following correctly defines a function that takes a structure as an argument?

9. What will happen if you try to access a member of a structure through a null pointer?

10. How do you return a structure from a function?

11. Which operator is used to access structure members through a pointer?

12. What is the output of the following code?

struct Point {
                    int x;
                    int y;
                };
                
                struct Point p = {3, 4};
                printf("%d", p.x);

13. What type of variable is created when defining a structure without a name?

14. What is the primary use of using structures in C?

15. How can you initialize a structure in C?

16. What will be the output of this code?

struct stud {
                    char name[80];
                    int roll;
                    float mark;
                } s1 = {"John", 101, 85.5};
                
                printf("%s", s1.name);

17. Which of the following can be a member of a structure?

18. Which statement is true regarding unions and structures?

19. How do you define a structure with a member that is another structure?

20. What is the default access specifier for structure members in C?

21. What is an array in C?

22. What is a structure in C?

23. How do you access an array element?

24. How do you access a structure member?

25. Can an array hold elements of different data types?

26. Can a structure hold an array as a member?

27. What is the default size of an array in C?

28. How do you declare a structure that includes an array?

29. What happens if you access an out-of-bounds index in an array?

30. What happens if you access a member of a structure that is not initialized?

31. How do you define an array of structures?

32. Which of the following can be members of a structure?

33. How do you initialize an array of integers with 5 elements?

34. Can a structure contain another structure?

35. Which has a fixed size: array or structure?

36. What is the size of a structure with two int members?

37. What is the output of this code?

                    struct stud {
                        int roll;
                        char name[20];
                    } student = {101, "Alice"};
                    
                    printf("%d", student.roll);
                

38. Can you use an array in a function as a parameter?

39. How do you pass a structure to a function?

40. Which is more memory efficient for storing multiple related data of the same type?

41. What is a nested structure in C?

42. How do you access a member of a nested structure?

43. What is the purpose of using nested structures?

44. How do you declare a nested structure?

45. What happens if you access a member of a nested structure that is not initialized?

46. Which operator is used to access members of a nested structure?

47. Can a structure member itself be a nested structure?

48. How do you define a nested structure in a function?

49. How can you initialize a nested structure?

50. In a nested structure, which keyword is used to define an inner structure?

51. What is the output of the following code?

                        struct emp {
                            char name[50];
                            struct dept {
                                int sal;
                                char degi[50];
                            } d;
                        };
                        struct emp e = {"Alice", {50000, "Manager"}};
                        printf("%s %d", e.name, e.d.sal);
                

52. Can a structure contain a pointer to another structure?

53. What is the correct way to declare a variable of a nested structure?

54. What keyword is used to define a structure?

55. How do you access the designation of an employee in a nested structure?

56. Which of the following statements is true about nested structures?

57. What is the size of a structure that contains two int members and one char member?

58. How can you pass a nested structure to a function?

59. How do you declare a structure with a nested structure and an array?

60. Can you use a nested structure to represent a complex data type such as a student with courses?

61. What is an array of structures in C?

62. How do you declare an array of structures?

63. Which of the following is true about the members of a structure?

64. What is the output of the following code snippet?

                    struct student {
                        char name[20];
                        int roll;
                    };
                    struct student s[2] = {{"Alice", 1}, {"Bob", 2}};
                    printf("%s", s[0].name);
                

65. What does the fflush(stdin) function do in the context of input?

66. What is the purpose of passing structures to functions?

67. How can you pass a structure to a function by reference?

68. In the context of structures, what does getch() do?

69. What will be the output of this code?

                            struct stud {
                                char name[20];
                                int roll;
                            };
                            struct stud s = {"Alice", 1};
                            printf("%d", s.roll);
                

70. How do you access a member of a structure within an array?

71. Which of the following statements is true about structure members?

72. What happens if you try to access an uninitialized member of a structure?

73. Can a structure contain another structure as a member?

74. Which of the following is a valid way to declare a structure variable?

75. What is a self-referential structure?

76. Which statement about structure members is correct?

77. Which function is used to read a string from the standard input?

78. How do you display the entire content of an array of structures?

79. What happens when a structure is passed by value to a function?

80. Which of the following is an advantage of using structures?

81. What happens when a structure variable is passed to a function in C?

82. How do you define a structure in C?

83. In the given program, what is the type of the member "name" in the "student" structure?

84. What does the display() function do in the provided code?

85. Which operator is used to access the members of a structure?

86. How can you ensure that a pointer to a character in a structure points to valid memory?

87. In the function call display(o);, what does o represent?

88. What will be the output of the given program?

                    struct student {
                        char *name;
                        int age;
                        float per;
                    };
                    struct student o = {"RAM", 25, 75.5};
                    display(o);
                

89. What does the return 0; statement indicate in the main() function?

90. If the structure is modified in the display() function, what happens to the original structure in the main() function?

91. What is the purpose of using a pointer for the "name" member in the structure?

92. Which of the following statements is true about passing structures to functions?

93. Can a function return a structure in C?

94. What is the output of the following code snippet?

                    struct student {
                        char *name;
                        int age;
                        float per;
                    };
                    struct student o = {"Alice", 22, 88.5};
                    printf("%s", o.name);
                

95. What will happen if you try to print an uninitialized pointer member in a structure?

96. What does the printf() function do in the display() function?

97. How do you pass a structure to a function by reference?

98. Which of the following correctly defines a structure in C?

99. What is the effect of using void display(struct student o) instead of void display(struct student *o)?

100. Which of the following is NOT a valid way to declare a structure variable?

101. What is the purpose of the typedef keyword in C?

102. How do you define a new alias for an existing data type using typedef?

103. Which of the following correctly defines an alias for unsigned int as unit?

104. What is the output of the following code?

                typedef struct {
                    int x;
                    int y;
                } point;
                point p = {10, 20};
                printf("%d %d", p.x, p.y);
                

105. What does typedef struct students { ... } stu; achieve?

106. In the statement typedef int* ptr;, what does ptr represent?

107. How can typedef improve code readability when using structures?

108. What is the output of the following code snippet?

                    typedef int Arr[4];
                    Arr temp = {1, 2, 3, 4};
                    printf("%d", temp[2]);
                

109. Which statement is true about typedef compared to #define?

110. Which of the following is NOT a valid use of typedef?

111. What is the main difference between typedef and #define?

112. How would you declare a pointer to a structure using typedef?

113. What is the output of the following code?

                typedef int* ptr;
                ptr p1, p2;
                int x = 10;
                p1 = &x;
                printf("%d", *p1);
                

114. When using typedef with arrays, what does it allow you to do?

115. How would you declare an array of 10 integers using typedef?

116. Which statement about typedef is FALSE?

117. Can you use typedef to create an alias for a function pointer?

118. What will happen if you do not include a semicolon at the end of a typedef declaration?

119. Which of the following is a valid definition of a typedef for a function that returns an integer and takes two integers as arguments?

120. How do you declare a variable st of type stu, where stu is defined using typedef for a structure?